<template>
  <div>
    <h2>精品推荐</h2>
    <div
      class="shang"
      @click="clickItem(item.id)"
      v-for="item in items"
      :key="item.id">
      <img :src="item.pic" alt />
      <div class="tlite">
        <h3>{{item.name | subStr}}</h3>
        <p class="tlite-p">{{item.characteristic | subStr(35)}}</p>
        <div class="pic">
          <p>
            {{item.minPrice | currency('￥')}}
            <span>{{item.originalPrice | currency('￥')}}</span>
          </p>
          <van-icon @click.stop="clickAddItem(item)" name="cart" size="28" color="red" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { currency, subStr } from '@/filters'
export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickItem (id) {
      this.$emit('clickItem', id)
    },
    clickAddItem (item) {
      // 点击加入购物车按钮
      this.$emit('clickAddItem', item)
      // console.log(item)
    }
  },
  filters: {
    currency,
    subStr
  }
}
</script>

<style lang="scss" scoped>
h2{
  font-size: 30px;
  text-align: center;
}
.shang{
  display: flex;
  background: rgb(243,245,247);
  height: 150px;
  margin-top: 7px;
  img{
    width: 150px;
  }
  .tlite{
    flex: 1;
    margin-left: 2px;
    background: #fff;
    padding-right: 10px;
    position: relative;
    h3{
      font-size: 22px;
      margin:5px 0;
      padding: 0;
    }
    &-p{
      margin-right: 15px;
      color: #666;
    }
    .pic{
      display: flex;
      justify-content: space-between;
      width: 93%;
      position: absolute;
      bottom: 5px;
      left: 0;
      p{
        margin: 0;
        color: rgb(255, 0, 76);
        span{
          margin-left: 5px;
          font-size: 14px;
          color: #666;
          text-decoration: line-through;
        }
      }
    }
  }
}
</style>
